import Vue from "vue"
import Vuex from "vuex"
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)
export default new Vuex.Store({
    plugins: [
        // 默认储存在localstorage
        createPersistedState({
           reducer:((state)=>{
                return {
                    ...state
                }
           })
        })
    ],
    state:{
        laseSearch:[],
        confirmbuy:[],
        isShow:false,
        collectdata:[]
    },
    mutations:{
        //更改laseSearch
     pushlaseSearch(state,val){
        state.laseSearch.push(val)
       },
    changebuy(state,buy){
       state.confirmbuy = buy
    },
    deleconfirmbuy(state){
        state.laseSearch = []
    },
    changeIsshow(state,show){
        return state.isShow = show
    },
    changecollectdata(state,payload){
            if(payload.what =="y"){
                state.collectdata.push(payload.who)
            }else if(payload.what == 'no'){
                state.collectdata = state.collectdata.filter(item => item.proid!= payload.who.proid)
                console.log('state.collectdata: ', state.collectdata);
            }
            return state.collectdata
    }
    }
})
//设置路由导航守卫

